const { ccclass, property } = cc._decorator;

import { app } from '../../../app/app';
import { menu } from '../../../app/decorator';
import { effecNamesEnum } from '../../../app/executor';
import BaseButtonTouch from './base/BaseButtonTouch';

@ccclass
@menu(__filename, '触摸音效')
export default class TouchEffect extends BaseButtonTouch {
    @property
    _effectName: string = effecNamesEnum[0] || '';
    @property({
        type: cc.Enum(effecNamesEnum)
    })
    get effectName(): number {
        const num = this._effectName ? effecNamesEnum[this._effectName] : 0;
        return typeof num === 'undefined' ? -1 : num;
    }
    set effectName(value) {
        this._effectName = effecNamesEnum[value];
    }

    onLoad() {
        const node = this.target || this.node;
        node.on(this.timeEvent, function () {
            effecNamesEnum[this.effectName] && app.manager.sound.playEffect({
                name: effecNamesEnum[this.effectName] as any
            });
        }, this);
    }
}
